﻿public class Solution {
    public int FindLength(int[] nums1, int[] nums2)
    {
        int[,] dp = new int[nums1.Length + 1, nums2.Length + 1];

        int res = 0;
        for (int i = 1; i <= nums1.Length; i++)
        {
            for (int j = 1; j <= nums2.Length; j++)
            {
                if (nums1[i-1] == nums2[j-1]) dp[i, j] = dp[i - 1, j - 1] + 1;
                if (res < dp[i, j]) res = dp[i, j];
            }
        }

        return res;
    }

    public static void Main(string[] args)
    {
        int[] nums1 = [1, 2, 3, 2, 1], nums2 = [3, 2, 1, 4, 7];
        Solution solution = new Solution();
        int res = solution.FindLength(nums1, nums2);
        Console.WriteLine(res);
    }
}